package com.cmsz.paydemo.function;

import java.io.IOException;

import com.cmsz.paydemo.util.FileUtil;
import com.cmsz.paydemo.util.HttpClientUtil;
import com.cmsz.paydemo.util.HttpClientUtil.NotificationProcessor;
import com.cmsz.paydemo.util.SignUtil;
import com.cmsz.paydemo.util.SimpleHttpServer2;

public class RefundDemo {
	public static void main(String[] args) throws Exception {
		String requestData = FileUtil.getData("refundReqData.xml");
		 requestData = SignUtil.sign(requestData);
		String responseData = HttpClientUtil.sendRequest("refund", requestData,
				new NotificationProcessor() {
					public void processNotification() throws IOException {
						//这里用另一个线程接受异步结果通知
				        new Thread(new Runnable() {  
				            public void run() { 
				            	try {
									Thread.sleep(1000);
									new SimpleHttpServer2().service();
								} catch (InterruptedException e) {
									e.printStackTrace();  
								} catch (Exception e) {
									// TODO Auto-generated catch block  
									e.printStackTrace();  
								}
				            }  
				        }).start();
					}
				});
		System.out.println("同步返回报文："+responseData);
		//报文验签
		Boolean signFlag = SignUtil.checkSign(responseData);
		System.out.println("同步返回报文验签结果："+signFlag);
		// create form html and print
	}
}
